$(document).ready(function() {

	// 用户注册
	$("#form_login").validate({
		rules: {
			username: {
				required: true
			},
			password: {
				required: true
			}
		},
		messages: {
			username: {
				required: "请输入用户名"
			},
			password: {
				required: "请输入密码"
			}
		}
	});

	//ajax提交表单
	$("#form_login").submit(function() {
		if($("#form_login").valid() == true)
		{
			$.ajax({type:"POST", url:"/member/login.html", data:$('#form_login').formSerialize(), dataType:"json", success:function (data){
				if(data.statusCode == 200)
				{
					$("#bbs_login").attr("src", data.bbs_login);
					window.location.href=data.forwardUrl;
				}
				else if(data.statusCode = 300)
				{
					alert(data.message);
					//凡是登录出错的，一律跳转到登录页面
					window.location.href='/member/login.html';
				}
				else
				{
					alert("操作出错");
				}
			}});
		}
		return false;
	});
	recoverByCode =function()
	{
		$("#passportForm").ajaxSubmit({
			dataType:"json",
			url:'/member/getpassword.html',
			type:'post',
			beforeSubmit:function(){
			if($.trim($("#password").val()) != $.trim($("#confirmPassword").val()))
			{
				alert("两次密码输入不一致！");
				$("#password").focus();
				return false;
			}
			if($.trim($("#password").val()).length <6)
			{
				alert("密码不能少于6个字符！");
				$("#password").focus();
				return false;
			}
			if($.trim($("#userName").val()) == '')
			{
				alert("请输入用户名！");
				$("#userName").focus();
				return false;
			}
		},
				success:function (data){
					if(data.result == 'success')
					{
						window.location.href= '/member/login.html';
					}
					else if(data.result = 'fail')
					{
						alert(data.msg);
					}
					else
					{
						alert("操作出错");
					}
				}
			});
	}
});